#ifndef _SUB_DEVICE_H
#define _SUB_DEVICE_H
#include "gd32e23x.h"
#define  FMC_PAGE_SIZE           ((uint16_t)0x400U)
#define  SUB_DEV_FLASH_ADDR  ((uint32_t)0x0800F800U)
#define RF_CMD_SEND_TIME          3000

void sub_dev_input_handle(uint8_t *ptr);
void fmc_read(uint32_t address, uint32_t *data, uint16_t len);
void fmc_program(uint32_t address, uint32_t *data, uint16_t len);
void fmc_erase_pages(uint32_t Addr);
int StringToHex(char *str, unsigned char *out, unsigned int *outlen);
void report_sub_dev_status(uint8_t *pt);
uint8_t get_download_cmd_cnt(void);
uint8_t gateway_handle(uint8_t dpid,const uint8_t value[], uint16_t length);
uint8_t record_joinin_net_success_subdev_in_flash(void);
void read_sub_dev_flash(void);
uint8_t remove_sub_dev_in_flash(uint32_t id);
uint8_t sub_dev_dp_handle(uint8_t dpid,const uint8_t value[], uint16_t length,uint8_t* sub_id);
void sub_dev_timing_int_handler(void);
void gateway_event_handle_mainloop(void);
void start_subdev_searching_or_abort(void);
void subdev_out_search_bind_mode(void);
void HexDataSwitchPosition(uint32_t *t);
uint8_t is_id_equal(uint8_t *id_buf);
void read_unbind_sub_dev_flash(void);
void subdev_query_mainloop(void);
uint8_t subdev_onoff_line_judge(uint8_t *ptr_id);
void factory_reset_by_app(void);
void factory_reset_by_key(void);
void wait_poll_all_subdev_status_for_sync(void);


#endif

